// pages/index3/index3.js
var common = require("../../utils/Conmon.js");

var appData = getApp().globalData;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    viewmodel: true,
    ShopID: 0,
    Logo: "",
    ShopName: "",
    BackgroundImg: "",
    TodayIncome: 0,
    MonthIncome: 0,
    AllIncome: 0,
    AdminDoamin: ""
  },
  viewModel: function() {
    this.setData({
      viewmodel: !(this.data.viewmodel),
    })
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    common.pageInit(function() {});
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    this.LoadShopInfo();
    this.LoadAdminDomain();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  LoadShopInfo: function() {
    var that = this;
    wx.request({
      url: appData.apiurl + "/mobile/api/Unionstore/GetShop",
      data: {
        "CustId": appData.custID,
        "UserId": wx.getStorageSync('UserInfo').UserID
      },
      method: 'GET',
      header: {
        'content-type': 'application/json',
        'X_ManuName': appData.manuName
      },
      success: function(res) {
        if (res.data.code == 1200 && res.data.content != null) {

          //读取商店信息加载
          var model = res.data.content;
          that.setData({
            ShopID: model.ID,
            Logo: appData.imgurl + model.Logo,
            ShopName: model.ShopName,
            BackgroundImg: appData.imgurl + model.BackgroundImg
          });

          that.loadIncome(model.ID);

        }


      },
      fail: function() {


      },
      complete: function() {

      }
    })

  },
  loadIncome: function(UnionStoreId) {

    var that = this;
    wx.request({
      url: appData.apiurl + "/mobile/api/OrderInfo/SumUnionShopIncome",
      data: {
        "custId": appData.custID,
        "UnionStoreId": UnionStoreId
      },
      method: 'GET',
      header: {
        'content-type': 'application/json',
        'X_ManuName': appData.manuName
      },
      success: function(res) {
        if (res.data.code == 1200 && res.data.content != null) {

          //读取商店信息加载
          var model = res.data.content;
          that.setData({
            TodayIncome: model.TodayIncome,
            MonthIncome: model.MonthIncome,
            AllIncome: model.AllIncome

          });



        }


      },
      fail: function() {


      },
      complete: function() {

      }
    })
  },
  LoadAdminDomain: function() {

    var that = this;
    wx.request({
      url: appData.apiurl + "/mobile/api/Unionstore/GetDomain",
      data: {
        "custID": appData.custID
      },
      method: 'GET',
      header: {
        'content-type': 'application/json',
        'X_ManuName': appData.manuName
      },
      success: function(res) {
        that.setData({
          AdminDoamin: res.data.msg


        });
      },
      fail: function() {


      },
      complete: function() {

      }
    })
  },
  Copy: function() {
    var that = this;
    wx.setClipboardData({
      data: that.data.AdminDoamin,
      success: function(res) {

        wx.showModal({
          title: '提示',
          content: '复制成功',
          success: function(res) {

          }
        })
      }
    });
  },
  linkTo: function() {
    wx.navigateTo({
      url: '/pages/UnionStoreOrderList/UnionStoreOrderList?ShopID=' + this.data.ShopID
    })

  }
})